//
//  YSExperienceOrderDetailFooterHeaderView.m
//  Yueshi
//
//  Created by Northwan on 15/8/5.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSExperienceOrderDetailFooterHeaderView.h"

#define TEXT_FONT 15

@interface YSExperienceOrderDetailFooterHeaderView()
@property (strong, nonatomic) UILabel *voucherTipLabel;
@property (strong, nonatomic) UILabel *voucherLabel;
@property (strong, nonatomic) UIView *spliteView;
@property (strong, nonatomic) UILabel *totalPriceLabel;

@end

@implementation YSExperienceOrderDetailFooterHeaderView

-(void)setPrice:(NSString *)price voucherAmount:(float)voucherAmount{
    [self setPrice:price voucherAmount:voucherAmount volumeCount:0];
}

-(void)setPrice:(NSString *)price voucherAmount:(float)voucherAmount volumeCount:(NSInteger)volumeCount{
    [self setBackgroundColor:PUBLIC_CARD_BG];
    
    CGFloat spliteY = YSPublicXInset;
    
    if(voucherAmount){
        NSString *voucherTipText = @"代金券优惠:";
        CGSize voucherTipTextSize = [voucherTipText sizeWithFont:SYS_FONT(TEXT_FONT)];
        UILabel *voucherTipLabel = [[UILabel alloc]init];
        [voucherTipLabel setText:voucherTipText];
        [voucherTipLabel setFont:SYS_FONT(TEXT_FONT)];
        [voucherTipLabel setTextColor:ThemeColor];
        [voucherTipLabel setFrame:CGRectMake(YSPublicXInset,YSPublicXInset, voucherTipTextSize.width, voucherTipTextSize.height)];
        [self addSubview:voucherTipLabel];
        _voucherTipLabel = voucherTipLabel;
        
        //代金券减免价格
        NSString *voucherText = [NSString stringWithFormat:@"-¥%.1f",voucherAmount];
        CGSize voucherTextSize = [voucherText sizeWithFont:SYS_FONT(TEXT_FONT)];
        UILabel *voucherLabel = [[UILabel alloc]init];
        [voucherLabel setFont:SYS_FONT(TEXT_FONT)];
        voucherLabel.frame = CGRectMake(SCREENW-YSPublicXInset-voucherTextSize.width, CGRectGetMinY(voucherTipLabel.frame), voucherTextSize.width, TEXT_FONT);
        [voucherLabel setTextColor:ThemeColor];
        [voucherLabel setText:voucherText];
        [self addSubview:voucherLabel];
        _voucherLabel = voucherLabel;
        ;
        
        UIView *spliteView = [[UIView alloc ]initWithFrame:CGRectMake(YSPublicXInset, CGRectGetMaxY(voucherLabel.frame)+YSPublicXInset, SCREENW-YSPublicXInset*2, 0.5)];
        [spliteView setBackgroundColor:SPLIT_LINE_COLOR];
        [self addSubview:spliteView];
        _spliteView = spliteView;
        
        
        spliteY = CGRectGetMaxY(spliteView.frame);
    }
    
    //总价
    NSString *totalPriceText = [NSString stringWithFormat:@"合计:¥%@",price];
    CGSize totalPriceTextSize = [totalPriceText sizeWithFont:[UIFont boldSystemFontOfSize:TEXT_FONT]];
    UILabel *totalPriceLabel = [[UILabel alloc]init];
    [totalPriceLabel setFont:[UIFont boldSystemFontOfSize:TEXT_FONT]];
    totalPriceLabel.frame = CGRectMake(SCREENW-YSPublicXInset-totalPriceTextSize.width, spliteY+YSPublicXInset, totalPriceTextSize.width, TEXT_FONT);
    [totalPriceLabel setTextColor:publicTextColor];
    [totalPriceLabel setText:totalPriceText];
    [self addSubview:totalPriceLabel];
    _totalPriceLabel = totalPriceLabel;
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(totalPriceLabel.frame)+YSPublicXInset, SCREENW, YSPublicXInset)];
    [lineView setBackgroundColor:PUBLIC_BG];
    [self addSubview:lineView];
    
    CGFloat h = CGRectGetMaxY(lineView.frame);
    
    if(volumeCount>0){
        //体验券:
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(YSPublicXInset, CGRectGetMaxY(lineView.frame)+YSPublicXInset, SCREENW, 15)];
        [label setText:@"体验券"];
        [label setFont:SYS_FONT(15)];
        [self addSubview:label];
        h = CGRectGetMaxY(label.frame)+YSPublicXInset;
    }
    
    self.frame = CGRectMake(0, 0, SCREENW,h);
}

@end
